qx.Class.define("elpintao.frms.clientes.windowCtaCte",
{
	extend : controles.window.Window,
	construct : function (appMain, cta_cte)
	{
		this.base(arguments);

	this.set({
		caption: "Cta.Cte.",
		width: 300,
		height: 200,
		showMinimize: false,
		showMaximize: false
	});
	this.setLayout(new qx.ui.layout.Canvas());
	
	this.addListenerOnce("appear", function(){
		txtInteres.focus();
	});
	
	
	var modelForm = null;
	var numberformatMonto = new qx.util.format.NumberFormat("en").set({groupingUsed: false, maximumFractionDigits: 2, minimumFractionDigits: 2});
	
	
	var form = new qx.ui.form.Form();
	
	var txtInteres = new qx.ui.form.Spinner();
	txtInteres.setRequired(true);
	txtInteres.setNumberFormat(numberformatMonto);
	form.add(txtInteres, "Interes", null, "interes");
	
	var txtLimite_mensual = new qx.ui.form.Spinner();
	txtLimite_mensual.setRequired(true);
	txtLimite_mensual.setNumberFormat(numberformatMonto);
	form.add(txtLimite_mensual, "Lim.mensual", null, "limite_mensual");
	
	
	var slbEstado = new qx.ui.form.SelectBox();
	slbEstado.add(new qx.ui.form.ListItem("Verde", null, "V"));
	slbEstado.add(new qx.ui.form.ListItem("Amarillo", null, "A"));
	slbEstado.add(new qx.ui.form.ListItem("Rojo", null, "R"));
	form.add(slbEstado, "Estado", null, "estado");
	
	
	var formView = new qx.ui.form.renderer.Single(form);
	
	this.add(formView, {left: 0, top: 0})
	
	var controllerForm = new qx.data.controller.Form(null, form);
	
	
	
	
	
	
	if (cta_cte.id_cta_cte==null) {
		modelForm = controllerForm.createModel(true);
	} else {
		modelForm = qx.data.marshal.Json.createModel(cta_cte);
		controllerForm.setModel(modelForm);
	}
	
	


	var commandEsc = new qx.ui.core.Command("Esc");
	this.registrarCommand(commandEsc);
	commandEsc.addListener("execute", function(e){
		btnCancelar.execute();
	});
	
	var btnAceptar = new qx.ui.form.Button("Aceptar");
	btnAceptar.addListener("execute", function(e){
		if (form.validate()) {
			var p = qx.util.Serializer.toNativeObject(modelForm);
			p.id_cliente = cta_cte.id_cliente;
			if (cta_cte.id_cta_cte==null) p.id_cta_cte = "0";
	
			var rpc = new qx.io.remote.Rpc("services/", "elpintao.Clientes");
			try {
				var resultado = rpc.callSync("alta_modifica_cta_cte", p);
			} catch (ex) {
				alert("Sync exception: " + ex);
			}
	
			this.fireDataEvent("aceptado", resultado);
			btnCancelar.execute();
		} else {
			var items = form.getItems();
			for (var item in items) {
				if (!items[item].isValid()) {
					items[item].focus();
					break;
				}
			}			
		}
	}, this);

	var btnCancelar = new qx.ui.form.Button("Cancelar");
	btnCancelar.addListener("execute", function(e){
		this.destroy();
	}, this);
	
	this.add(btnAceptar, {left: 10, bottom: 0});
	this.add(btnCancelar, {left: 150, bottom: 0});
		
		
		
	},
	members : 
	{

	}
});